/*********************************************************************************
  *FileName:  nsuc16xx_bemfc.h
  *Version:   V1.0
  *Date:      2024-03-04
**********************************************************************************/

#ifndef  __nsuc16xx_bemfc_H__
#define  __nsuc16xx_bemfc_H__

/***************************************Includes***********************************/
#include "nsuc16x0.h"

/***************************************Macros***********************************/
#define BEMFC_FilterTime_Disable					((uint8_t)0x00)	/* Filtering is disabled */
#define BEMFC_FilterTime_0us6_0us8					((uint8_t)0x01)	/* 0.6 us- 0.8 us */
#define BEMFC_FilterTime_1us_1us2					((uint8_t)0x02)	/* 1.0 us- 1.2 us */
#define BEMFC_FilterTime_3us_3us2					((uint8_t)0x03)	/* 3.0 us- 3.2 us */

#define BEMFC_BlankingTime_Disable					((uint8_t)0x00)	/* BlankingTime is disabled */
#define BEMFC_BlankingTime_1us4_1us6				((uint8_t)0x01)	/* 1.4us- 1.6us */
#define BEMFC_BlankingTime_3us_3us2					((uint8_t)0x02)	/* 3.0 us- 3.2us */
#define BEMFC_BlankingTime_4us6_4us8				((uint8_t)0x03)	/* 4.6us- 4.8us */
#define BEMFC_BlankingTime_6us2_6us4				((uint8_t)0x04)	/* 6.2us- 6.4us */
#define BEMFC_BlankingTime_7us8_8us					((uint8_t)0x05)	/* 7.8us- 8.0us */
#define BEMFC_BlankingTime_9us4_9us6				((uint8_t)0x06)	/* 9.4us- 9.6us */
#define BEMFC_BlankingTime_11us_11us2				((uint8_t)0x07)	/* 11.0us- 11.2us */
#define BEMFC_BlankingTime_12us6_12us8				((uint8_t)0x08)	/* 12.6us- 12.8us */
#define BEMFC_BlankingTime_14us2_14us4				((uint8_t)0x09)	/* 14.2us- 14.4us */
#define BEMFC_BlankingTime_15us8_16us				((uint8_t)0x0A)	/* 15.8us- 16.0us */
#define BEMFC_BlankingTime_17us4_17us6				((uint8_t)0x0B)	/* 17.4us- 17.6us */
#define BEMFC_BlankingTime_19us_19us2				((uint8_t)0x0C)	/* 19.0us- 19.2us */
#define BEMFC_BlankingTime_20us6_20us8				((uint8_t)0x0D)	/* 20.6us- 20.8us */
#define BEMFC_BlankingTime_22us2_22us4				((uint8_t)0x0E)	/* 22.2us- 22.4us */
#define BEMFC_BlankingTime_23us8_24us				((uint8_t)0x0F)	/* 23.8us- 24.0us */

#define BMFC_Out_NO_Opposite						((uint8_t)0x00)	/*  output is not inversion */
#define BMFC_Out_Opposite							((uint8_t)0x01)	/*  Output inversion */

#define BEMFC_Event_Source_0						((uint8_t)0x00) /* epwm_hs[0] */
#define BEMFC_Event_Source_1						((uint8_t)0x01) /* epwm_ls[0] */
#define BEMFC_Event_Source_2						((uint8_t)0x02) /* epwm_hs[1] */
#define BEMFC_Event_Source_3						((uint8_t)0x03) /* epwm_ls[1] */
#define BEMFC_Event_Source_4						((uint8_t)0x04) /* epwm_hs[2] */
#define BEMFC_Event_Source_5						((uint8_t)0x05) /* epwm_ls[2] */
#define BEMFC_Event_Source_6						((uint8_t)0x06) /* epwm_hs[3] */
#define BEMFC_Event_Source_7						((uint8_t)0x07) /* epwm_ls[3] */
#define BEMFC_Event_Source_8						((uint8_t)0x08) /* epwm_hs[0] || epwm_ls[0] */
#define BEMFC_Event_Source_9						((uint8_t)0x09) /* epwm_hs[1] || epwm_ls[1] */
#define BEMFC_Event_Source_10						((uint8_t)0x0A) /* epwm_hs[2] || epwm_ls[2] */
#define BEMFC_Event_Source_11						((uint8_t)0x0B) /* epwm_hs[3] || epwm_ls[3] */
#define BEMFC_Event_Source_12						((uint8_t)0x0C) /* （epwm_hs[0] || epwm_ls[0]） ^ （epwm_hs[1] || epwm_ls[1]） */
#define BEMFC_Event_Source_13						((uint8_t)0x0D) /* （epwm_hs[0] || epwm_ls[0]） ^ （epwm_hs[2] || epwm_ls[2]） */
#define BEMFC_Event_Source_14						((uint8_t)0x0E) /* （epwm_hs[0] || epwm_ls[0]） ^ （epwm_hs[3] || epwm_ls[3]） */
#define BEMFC_Event_Source_15						((uint8_t)0x0F) /* （epwm_hs[1] || epwm_ls[1]） ^ （epwm_hs[2] || epwm_ls[2]） */
#define BEMFC_Event_Source_16						((uint8_t)0x10) /* （epwm_hs[1] || epwm_ls[1]） ^ （epwm_hs[3] || epwm_ls[3]） */
#define BEMFC_Event_Source_17						((uint8_t)0x11) /* （epwm_hs[2] || epwm_ls[2]） ^ （epwm_hs[3] || epwm_ls[3]） */
#define BEMFC_Event_Source_18						((uint8_t)0x12) /* （epwm_hs[0] || epwm_ls[0]） ^ （epwm_hs[1] || epwm_ls[2]） ^（epwm_hs[2] || epwm_ls[2]） */

#define EventTest_Disable							((uint8_t)0x00)	/* Test of event is disable */
#define EventTest_Low								((uint8_t)0x01)	/* Test of event is in low level */
#define EventTest_High								((uint8_t)0x02)	/* Test of event is in high level */
#define EventTest_ALL								((uint8_t)0x03)	/* Test of event is in high and low level */

#define Event_ITSource_Disable						((uint8_t)0x00)	/* EXIT of event is disable */
#define Event_ITSource_Raise						((uint8_t)0x01)	/* EXIT of event in raise edge */
#define Event_ITSource_Down							((uint8_t)0x02)	/* EXIT of event in down edge */
#define Event_ITSource_AllEdge						((uint8_t)0x03)	/* EXIT of event in all edge */

#define BEMFC_Hysteresis_0mV						((uint8_t)0x00)	/* The hysteresis size of BEMFC is 0mv */
#define BEMFC_Hysteresis_10mV						((uint8_t)0x01)	/* The hysteresis size of BEMFC is 10mv */
#define BEMFC_Hysteresis_20mV						((uint8_t)0x02)	/* The hysteresis size of BEMFC is 20mv */
#define BEMFC_Hysteresis_40mV						((uint8_t)0x03)	/* The hysteresis size of BEMFC is 40mv */

#define BEMFC_Input_Voltage							((uint8_t)0x00)	/* BEMFC channel  Voltage sensing input */
#define BEMFC_Input_Current							((uint8_t)0x01)	/* BEMFC channel  Current sensing input */

#define BEMFC_CurrentSource0						((uint8_t)0x00)	/* BEMFC channel 0 Current sensing source Located in LS[0] */
#define BEMFC_CurrentSource1						((uint8_t)0x01)	/* BEMFC channel 0 Current sensing source Located in LS[1] */
#define BEMFC_CurrentSource2						((uint8_t)0x00)	/* BEMFC channel 1 Current sensing source Located in LS[2] */
#define BEMFC_CurrentSource3						((uint8_t)0x01)	/* BEMFC channel 1 Current sensing source Located in LS[3] */

#define BEMFC_ReferenceMode_Dream					((uint8_t)0x00)	/* Virtual star reference */
#define BEMFC_ReferenceMode_Voltage					((uint8_t)0x01)	/* Phase-voltage reference */

#define Current_ReferenceMode0						((uint8_t)0x00)	/* DAC0→BEMFC0 / DAC1→BEMFC1 */
#define Current_ReferenceMode1						((uint8_t)0x01)	/* DAC0→BEMFC2 / DAC1→BEMFC1 */
#define Current_ReferenceMode2						((uint8_t)0x02)	/* DAC0→BEMFC0 / DAC1→BEMFC2 */
#define Current_ReferenceMode3						((uint8_t)0x03)	/* reserved / reserved */
/***************************************Variables***********************************/
typedef struct
{
	uint8_t BEMFC_FilterTime;
	uint8_t BEMFC_OutDiretion;
	uint8_t BEMFC_BlankingTime;
	uint8_t BEMFC_Delay;
	uint8_t BEMFC_Input;
	uint8_t BEMFC_EventSource;
	uint8_t BEMFC_EventTest;
	
} BEMFC_InitTypeDef;

typedef struct
{
	uint8_t Event_Source;
	uint8_t Event_Test;
	uint8_t Event_EXIT_Source;
	
}EventConfig_InitTypeDef;

typedef struct
{
	uint8_t Current_Reference;
	uint8_t Reference_Mode;
	uint8_t Channel0_Current_Source;
	uint8_t Channel1_Current_Source;
	
}Reference_InitTypeDef;

void BEMFC0_Cmd(BEMFC_TypeDef *BEMFCx, FunctionalState NewState);
void BEMFC1_Cmd(BEMFC_TypeDef *BEMFCx, FunctionalState NewState);
void BEMFC2_Cmd(BEMFC_TypeDef *BEMFCx, FunctionalState NewState);
void BEMFC0_Init(BEMFC_TypeDef *BEMFCx, BEMFC_InitTypeDef *BEMFC_InitStruct);
void BEMFC1_Init(BEMFC_TypeDef *BEMFCx, BEMFC_InitTypeDef *BEMFC_InitStruct);
void BEMFC2_Init(BEMFC_TypeDef *BEMFCx, BEMFC_InitTypeDef *BEMFC_InitStruct);
void BEMFC_Congfig(BEMFC_TypeDef *BEMFCx, Reference_InitTypeDef *Reference_InitStruct);
void CLDAC_TRG0_EeventCmd(BEMFC_TypeDef *BEMFCx, FunctionalState NewState);
void CLDAC_EOP0_EeventCmd(BEMFC_TypeDef *BEMFCx, FunctionalState NewState);
void CLDAC_BufferCmd(BEMFC_TypeDef *BEMFCx, FunctionalState NewState);
void CLDAC0_Current_Limit(BEMFC_TypeDef *BEMFCx,uint16_t HARD_CURRENT_LIMIT_SET);
void CLDAC1_Current_Limit(BEMFC_TypeDef *BEMFCx,uint16_t HARD_CURRENT_LIMIT_SET);
void CLDAC_Cmd(BEMFC_TypeDef *BEMFCx, FunctionalState NewState);

#endif
/* [] END OF nsuc16xx_bemfc.h */
